package com.lsht.system.service.impl.siwei;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @author zyc
 * @date 2024/08/30 11:37
 */
public class SiweiDateUtils {
    public static String[] getYesterdayStartAndEndTime() {
        // 获取当前日期
        LocalDate today = LocalDate.now();

        // 获取昨日日期
        LocalDate yesterday = today.minusDays(1);

        // 昨日的开始时间
        LocalDateTime startOfYesterday = LocalDateTime.of(yesterday, LocalTime.MIDNIGHT);

        // 昨日的结束时间
        LocalDateTime endOfYesterday = LocalDateTime.of(yesterday, LocalTime.MAX);

        // 格式化时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        // 转换为字符串
        String startOfYesterdayStr = startOfYesterday.format(formatter);
        String endOfYesterdayStr = endOfYesterday.format(formatter);

        // 返回开始时间和结束时间的字符串数组
        return new String[]{startOfYesterdayStr, endOfYesterdayStr};
    }
}

